<?php

namespace App\Containers\AppSection\User\Actions;

use App\Containers\AppSection\Authentication\Tasks\GetAuthenticatedUserTask;
use App\Ship\Exceptions\NotFoundException;
use App\Ship\Parents\Actions\Action;
use App\Ship\Parents\Requests\Request;

class GetAuthenticatedUserAction extends Action
{
    public function run(Request $request): array
    {
        $user = app(GetAuthenticatedUserTask::class)->run();
        $profile = $request->profile();

        if (!$user) {
            throw new NotFoundException(__('ship::resource.not-found'));
        }

        return [
            'user' => $user,
            'profile' => $profile,
        ];
    }
}
